//widgetpp.cpp
/*    widgetpp - A simple C++ wrapper of DISLIN graphic library               */
/*                                                                            */
/*    Copyright (C) 2012  Mirko Cambi (email: mirko.cambi@gmail.com)          */
/*                                                                            */
/*    This program is free software: you can redistribute it and/or modify    */
/*    it under the terms of the GNU General Public License as published by    */
/*    the Free Software Foundation, either version 3 of the License, or       */
/*    (at your option) any later version.                                     */
/*                                                                            */
/*    This program is distributed in the hope that it will be useful,         */
/*    but WITHOUT ANY WARRANTY; without even the implied warranty of          */
/*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           */
/*    GNU General Public License for more details.                            */
/*                                                                            */
/*    You should have received a copy of the GNU General Public License       */
/*    along with this program.  If not, see <http://www.gnu.org/licenses/>.   */

#include "widgetpp.hpp"
#include "dislin.h"

using namespace wdgpp;

const unsigned int
   laid_out::vert = 0,
   laid_out::hori = 1,
   laid_out::form = 2;

Widgetpp::Widgetpp(const std::string &title, int width, unsigned int lo): _focus(0)
{
   swgtit(title.c_str());
   std::string slo = "VERT";
   if(lo == 1)
      slo = "HORI";
   else if(lo == 2)
      slo = "FORM";
   
   _id = wgini(slo.c_str());
   WIDGETPPS::instance().insert(std::make_pair(_id, this));
   
   swgwth(width);
}

Widgetpp::~Widgetpp()
{
}

int Widgetpp::add(const std::string &name, Wdg *wdg, int ip)
{
   boost::shared_ptr<Wdg> spw(wdg);
   
   if(ip == -999)
      ip = _id;
   
   int wdg_id = (*wdg)(ip);
   _wdgs.insert(std::make_pair(name, spw));
   (*spw)._id = wdg_id;
      
   return wdg_id;   
}

int Widgetpp::id() const
{
   return _id;   
}

void Widgetpp::set_focus(int id)
{
   _focus = id;   
}

void Widgetpp::draw() const
{
  swgatt(_id, "ACTIVE", "STATUS");
  if(_focus)
     swgfoc(_focus);  

  // *** start callback loop ***
  wgfin();
}

